﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ShiXuLong.Model;

namespace ShiXuLong.Service.New
{
    public class User
    {
        ShoesEntities db = new ShoesEntities();

        /// <summary>
        /// 这是一个写死的方法，用来获取，第一个查询到的管理员用户
        /// 必要的时候可以更改，思路是给他传入，登录时候产生的用户id
        /// </summary>
        /// <returns></returns>
        public Model.User Getuser()
        {
            var lists1 = from c in db.Users select c;
            var lists = lists1.Where(p => p.UserTypeId == 2).ToList();
            var user = lists.FirstOrDefault();
            return user;
        }
        public Model.User GetUser1(int id)
        {
            var lists = from c in db.Users.Where(p => p.Id == id) select c;
            var list = lists.ToList();
            var user = list.FirstOrDefault();
            return user;
        }
        public int UpdateUser(Model.User user)
        {
            try
            {
                var list = db.Users.Where(p => p.Id == user.Id).ToList().SingleOrDefault();
                list.UserImage = user.UserImage;
                var re = db.SaveChanges();
                return re;
            }
            catch (Exception)
            {

                return 0;
            }


        }
       
        public int UpdateUserPwd(string newPwd,Model.User user)
        {
            try
            {
                var list = db.Users.Where(p => p.Id == user.Id).ToList().SingleOrDefault();
                list.UserPwd = newPwd;
                var re = db.SaveChanges();
                return re;
            }
            catch (Exception)
            {

                return 0;
            }


        }
    }
}
